package com.yra.controller.mall;

import com.yra.common.Constants;
import com.yra.common.IndexConfigTypeEnum;
import com.yra.controller.vo.NewBeeMallIndexCategoryVO;
import com.yra.domain.Carousel;
import com.yra.domain.IndexConfig;
import com.yra.domain.Product;
import com.yra.service.CarouselService;
import com.yra.service.CategoryService;
import com.yra.service.IndexConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: yrq
 * @Date: Create in 14:29 2019/12/5
 */
@RequestMapping
@Controller
public class IndexMallController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private CarouselService carouselService;
    @Autowired
    private IndexConfigService indexConfigService;

    @RequestMapping(value = {"/","index"},method = RequestMethod.GET)
    public ModelAndView goToIndex(HttpServletRequest request){
        ModelAndView mv = new ModelAndView("/mall/index");
        List<NewBeeMallIndexCategoryVO> categories = categoryService.indexCategoryByLevel();
        List<Carousel> carousels= carouselService.queryCarouselForIndex(Constants.INDEX_CAROUSEL_NUMBER);
        List<Product> hotProducts = indexConfigService.queryConfigForIndex(IndexConfigTypeEnum.INDEX_GOODS_HOT.getType(), Constants.INDEX_GOODS_HOT_NUMBER);
        List<Product> newProducts = indexConfigService.queryConfigForIndex(IndexConfigTypeEnum.INDEX_GOODS_NEW.getType(), Constants.INDEX_GOODS_NEW_NUMBER);
        List<Product> recommondProducts = indexConfigService.queryConfigForIndex(IndexConfigTypeEnum.INDEX_GOODS_RECOMMOND.getType(), Constants.INDEX_GOODS_RECOMMOND_NUMBER);


        request.setAttribute("carousels",carousels);
        request.setAttribute("hotProducts",hotProducts);
        request.setAttribute("newProducts",newProducts);
        request.setAttribute("recommondProducts",recommondProducts);
        request.setAttribute("categories",categories);
        return mv;
    }


}
